﻿//-------------------------------------------------------------------------------------------------------------------------------------
// Copyright (C) 2005 greatelsoft.com All Rights Reserved
//-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web.UI;
using GTS.Channel.Api.Entity;
using Pub.Class;
using GTS.Channel.Api.Helper;

namespace GTS.Channel.Api {
    /// <summary>
    /// 勤勉SMS和IVR的MO MT MR接收数据接口
    /// </summary>
    public class QinMian : ISMSIVR {
        /// <summary>
        /// SPCode
        /// </summary>
        public string SPCode = "QinMian";
        /// <summary>
        /// SMS MO的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMOData() {
            ChannelDealData info = new ChannelDealData();
            if (Request2.GetQInt("msg_type", 0) == 0) {
                //初始值           
                info.SPCode = SPCode;
                info.SMSKey = 1;
                info.IsHidden = false;
                info.Price = 10;
                info.DeviceCode = "GENERICDEVICE";
                // info.ResponseStatus = 1;
                info.MODate = DateTime.Now;
                //接收值
                info.Mobile = Request2.GetQ("mobile_number").Trim();
                info.ReceiveQuery = Request2.GetQ("content").Trim().UrlDecode();
                info.LinkID = Request2.GetQ("wamid").Trim();
                info.LongPhone = Request2.GetQ("gateway").Trim();

                if (info.Mobile.IsNullEmpty() || info.LinkID.IsNullEmpty() || info.ReceiveQuery.IsNullEmpty() || info.LongPhone.IsNullEmpty()) return null;

                string[] infos = info.ReceiveQuery.Split('_');
                if (infos.Length >= 4) {
                    info.MountCode = infos[1].ToInt();
                    info.GameCode = infos[2].PadLeft(5, '0');
                    info.ChargeCode = infos[3];
                } else {
                    info.MountCode = 493;
                    info.GameCode = "00999";
                    info.ChargeCode = "9";
                }
                //如果数据库中存在价格以数据库里为主
                ChannelInfo extInfo = Base.GetChannelInfo(SPCode, info.LongPhone, info.ReceiveQuery);
                if (extInfo.IsNotNull() && extInfo.ChannelName.IsNotNull()) {
                    info.Price = extInfo.Price.Value;
                    info.SMSKey = extInfo.CstCode;
                }
            } else if (Request2.GetQInt("msg_type", 0) == 1) {
                info.SPCode = SPCode;
                info.ResponseStatus = 1;
                info.MRDate = DateTime.Now;
                //接收值
                info.Mobile = Request2.GetQ("mobile_number").Trim();
                info.LinkID = Request2.GetQ("wamid").Trim();
            }

            return info;
        }
        /// <summary>
        /// SMS MT的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMTData() {
            return null;
        }
        /// <summary>
        /// SMS MR的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMRData() {
            return null;
        }
        /// <summary>
        /// IVR的参数数据
        /// </summary>
        /// <returns></returns>
        public IVRDealData GetIVRMRData() {
            return null;
        }
        /// <summary>
        /// 输出消息
        /// </summary>
        /// <param name="res"></param>
        public void Output(ResultEnum res) {
            Msg.WriteEnd(res == ResultEnum.Success ? "OK" : "Error");
        }
    }
}

